
//
//  HomeView.m
//  afn
//
//  Created by mac on 2018/5/7.
//  Copyright © 2018年 mac. All rights reserved.
//

#import "HomeView.h"
#import "HomeTableViewCell.h"
@implementation HomeView

-(void)creatView{
    _tableView=[BaseTableView new];
    [self addSubview:_tableView];
    [_tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.bottom.mas_equalTo(0);
    }];
    _tableView.backgroundColor=_LightGrey;
    _tableView.dataSource=self;
    _tableView.delegate=self;
    [self creatHeadView];
    
}
-(void)creatHeadView{
    UIImage *image=[UIImage imageNamed:@"pic-banner"];
    CGFloat height=image.size.height*(_mainW/image.size.width);
    
    UIView *headView=[UIView new];
    [headView setFrame:CGRectMake(0, 0,_mainW, height+130)];
    headView.backgroundColor=_LightGrey;
    _tableView.tableHeaderView=headView;
    NSMutableArray *imageArr=[NSMutableArray arrayWithCapacity:0];
    
    for (int i=0; i<_homeBannerArr.count; i++) {
        HomeBannerModel *bannerModel=[HomeBannerModel mj_objectWithKeyValues:_homeBannerArr[i]];
        [imageArr addObject:bannerModel.Carousel_path];
    }
    
    [gongju getHederImage:0 :CGRectMake(0, 0, _mainW, height) :imageArr :0 :headView :^(int value) {
        HomeBannerModel *bannerModel=[HomeBannerModel mj_objectWithKeyValues:_homeBannerArr[value]];
        NSLog(@"%@",bannerModel.Carousel_urll);
    }];
    
//    UIImageView *imageView=[UIImageView new];
//    [headView addSubview:imageView];
//    [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.top.right.mas_equalTo(0);
//        make.height.mas_equalTo(height);
//    }];
//    imageView.image=image;
    
    UIView *topView=[UIView new];
    [headView addSubview:topView];
    [topView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(20);
        make.right.mas_equalTo(-20);
        make.top.mas_equalTo(height-15);
        make.height.mas_equalTo(140);
    }];
    topView.backgroundColor=[UIColor whiteColor];
    topView.layer.cornerRadius=10;
    
    
    NSArray *nameArr=[NSArray arrayWithObjects:@"美发造型",@"美发护发",@"创意美甲",@"美容护肤", nil];
    NSArray *nameArr2=[NSArray arrayWithObjects:@"ico-meifa",@"ico-yangfa",@"ico-meijia",@"ico-meirong", nil];
    
    for (int i=0; i<4; i++) {
        UIView *TuWenView=[UIView new];
        [topView addSubview:TuWenView];
        [TuWenView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(10+(_mainW-60)/4*i);
            make.top.mas_equalTo(0);
            make.width.mas_equalTo((_mainW-60)/4);
            make.height.mas_equalTo(90);
        }];
        TuWenView.tag=i;
        
        UIImageView *imageview2=[UIImageView new];
        [TuWenView addSubview:imageview2];
        [imageview2 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.mas_equalTo(0);
            make.top.mas_equalTo(15);
            make.width.height.mas_equalTo(50);
        }];
        imageview2.image=[UIImage imageNamed:nameArr2[i]];
        
        UILabel *label=[UILabel new];
        [TuWenView addSubview:label];
        [label mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.mas_equalTo(0);
            make.top.mas_equalTo(imageview2.mas_bottom).mas_equalTo(10);
        }];
        label.text=nameArr[i];
        label.textColor=ColorWithRGB(29, 29, 29);
        label.font=[UIFont systemFontOfSize:14];
    }
    
    UIView *xianView=[UIView new];
    [topView addSubview:xianView];
    [xianView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(0);
        make.top.mas_equalTo(100);
        make.height.mas_equalTo(1);
    }];
    xianView.backgroundColor=_LightGrey;
    
    
    UIView *bottomView=[UIView new];
    [topView addSubview:bottomView];
    [bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(0);
        make.bottom.mas_equalTo(-10);
        make.top.mas_equalTo(xianView.mas_bottom);
    }];
    
    UIImageView *touTiaoImage=[UIImageView new];
    [bottomView addSubview:touTiaoImage];
    [touTiaoImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(0);
        make.left.mas_equalTo(10);
        make.width.mas_equalTo(70);
        make.height.mas_equalTo(31*70/129);
    }];
    touTiaoImage.image=[UIImage imageNamed:@"biaoqian"];
    
    UILabel *label=[UILabel new];
    [bottomView addSubview:label];
    [label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(touTiaoImage.mas_right).mas_equalTo(10);
        make.centerY.mas_equalTo(0);
        make.width.mas_equalTo(30);
        make.height.mas_equalTo(15);
    }];
    label.text=@"最新";
    label.textAlignment=NSTextAlignmentCenter;
    label.font=[UIFont systemFontOfSize:12];
    label.textColor=_backgroundColor;
    label.layer.cornerRadius=3;
    label.layer.borderColor=_backgroundColor.CGColor;
    label.layer.borderWidth=1;
    
    UIImageView *jianTouimage=[UIImageView new];
    [bottomView addSubview:jianTouimage];
    [jianTouimage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-10);
        make.centerY.mas_equalTo(0);
        make.width.mas_equalTo(12);
        make.height.mas_equalTo(18);
    }];
    jianTouimage.image=[UIImage imageNamed:@"arrow_right_black"];
    
    UILabel *tiShiLabel=[UILabel new];
    [bottomView addSubview:tiShiLabel];
    [tiShiLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(0);
        make.left.mas_equalTo(label.mas_right).mas_equalTo(5);
        make.right.mas_equalTo(jianTouimage.mas_right).mas_equalTo(-5);
    }];
    tiShiLabel.text=@"立即注册平台VIP，充多少送多少";
    tiShiLabel.textColor=ColorWithRGB(29, 29, 29);
    tiShiLabel.font=[UIFont systemFontOfSize:15];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _tableArr.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  
    HomeTableViewCell *cell=[[HomeTableViewCell alloc] init];
    HomeTableModel *model=[HomeTableModel mj_objectWithKeyValues:_tableArr[indexPath.row]];
    cell.viewController=self.viewController;
    cell.model=model;
    if (model.virtual_shop_id){
//        cell.num=_num;
        [cell setFrame:CGRectMake(0, 0, _mainW, [cell creatView])];
//        __weak typeof(self) weakSelf = self;
//        cell.customSelectedBlock = ^ (NSNumber *abc)
//        {
//            _num=abc;
//            NSIndexPath *indexPath=[NSIndexPath indexPathForRow:0 inSection:0];
//            [tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath,nil] withRowAnimation:UITableViewRowAnimationNone];
//
//        };
    }
    if (model.shop_id){
        [cell setFrame:CGRectMake(0, 0, _mainW, [cell creatView2])];
    }
    tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell;
    cell= [self tableView:tableView cellForRowAtIndexPath:indexPath];
    return cell.frame.size.height;
   
}
@end
